package com.demo.java.disruptor.netty.server;

import com.demo.java.disruptor.netty.common.DisruptorFactory;
import com.demo.java.disruptor.netty.common.DisruptorFactory.Producer;
import com.demo.java.disruptor.netty.common.TranslatorData;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class ServerMessageHandler extends ChannelInboundHandlerAdapter {
    private Producer producer;

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        super.channelActive(ctx);
        this.producer = DisruptorFactory.createProducer();
    }

    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        TranslatorData data = (TranslatorData) msg;
        this.producer.sendData(ctx, data, false);
    }
}
